package com.jerei.store.controller;

import com.jerei.store.entity.Product;
import com.jerei.store.service.impl.ProductServiceImpl;
import com.jerei.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController extends BaseController{
    @Autowired
    private ProductServiceImpl productService;

    @RequestMapping("/findProduct")
    public JsonResult<List<Product>> findProduct(){
        List<Product> list=productService.findProduct();
        return new JsonResult<>(OK,list);
    }

    @RequestMapping("/findProduct/time")
    public JsonResult<List<Product>> findProductByTime(){
        List<Product> list=productService.findProductByTime();
        return new JsonResult<>(OK,list);
    }

    @RequestMapping("/findById")
    public JsonResult<Product> findById(Integer id){
        Product product=productService.findById(id);

        return new JsonResult<>(OK,product);
    }

    @RequestMapping("/like")
    public JsonResult<List<Product>> findByLike(Integer index,String name){

        System.out.println("模糊查询的名字"+name);
        List<Product> list=productService.findByLike(name,index);
        System.out.println(list);
        return new JsonResult<>(OK,list);

    }


    @RequestMapping("/count")
    public JsonResult<Integer> findCount(String name){
        System.out.println("name="+name);
        Integer num=productService.findCount(name);
        System.out.println("num="+num);
        return new JsonResult<>(OK,num);

    }






}
